﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using System.Configuration;

namespace zjbks
{
    public partial class ShenHeXinXi : System.Web.UI.Page
    {
        int count = 1;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void allow_Click(object sender, EventArgs e)
        {
            string s1 = DateTime.Now.Year.ToString();
            BLL.BStudentInfo bStudent = new BLL.BStudentInfo();
            BLL.BZKZ bZKZ = new BLL.BZKZ();
            Model.StudentInfoEntity student = new Model.StudentInfoEntity();
            Model.ZKZEntity zKZ = new Model.ZKZEntity();
            foreach (GridViewRow grv in GridView1.Rows)
            {
                if(grv.RowType==DataControlRowType.DataRow)
                {
                    CheckBox cb = (CheckBox)grv.FindControl("cb");
                    if(cb.Checked)
                    {
                        student.ID= grv.Cells[0].Text.ToString();
                        string s2=grv.Cells[7].Text.ToString();
                        string s3 = count.ToString().PadLeft(4,'0');
                        student = bStudent.GetStudentInfo(student.ID);//不报名没有信息
                        student.stats = 1;
                        zKZ.ID = student.ID;
                        zKZ.KCnum = s3.Substring(0,2);
                        zKZ.Name = student.Name;

                        string sql = "select CollageNo from CollageInfo where CollageName='" + s2 + "'";
                        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["zjbksConnectionString"].ConnectionString);
                        SqlCommand cmd = new SqlCommand(sql);
                        Object ob = new Object();
                        cmd.Connection = conn;
                        conn.Open();
                        ob = cmd.ExecuteScalar();
                        s2 = ob.ToString();
                        conn.Close();
                        zKZ.RCollage = student.Collage;
                        zKZ.Number = s1 + s2 + s3;
                         zKZ.Seat = s3.Substring(s3.Length-2);
                        zKZ.Subject = student.Subject;
                        zKZ.Sex = student.Sex;
                        if (bStudent.ModStudentInfo(student)>0&&bZKZ.AddZKZ(zKZ)>0)
                        {
                            ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('已同意');</script>");
                        }
                        else
                        {

                        }
                    }
                }
            }
            count++;
        }
    }
}